#!/data/Software/mydan/perl/bin/perl -I/data/Software/mydan/Connector/lib -I/data/Software/mydan/Connector/private/lib
use strict;
use warnings;
use Logs;
use YAML::XS;
use LWP::UserAgent;

$| ++;

=head1 SYNOPSIS

    cookie => 'cookiestring',
    treeid =>
    point =>

    logs => 日志对象

=cut

my ( $pmspoint, %env );
BEGIN{
    use Configini;
    $pmspoint = Configini::get( 'pmspoint' );
    %env = Configini::env( 'pmspointenv' );
};

return sub
{
    my ( %param )= @_;
    my ( $cookie, $point, $treeid, $logs ) = @param{qw(cookie point treeid logs )};

    $treeid ||= 0;
    $logs = Logs->new( 'code.point' ) unless $logs;
#    $logs->die( "id not a number" ) unless $id =~ /^\d+$/;

    my $ua = LWP::UserAgent->new;
    $ua->default_header( %env ) if %env;

    my $treestr = '';
    if( defined $treeid )
    {
        if( $treeid )
        {
            $treestr = "&treeid=$treeid";
        }
        else
        {
            if( $point =~ /_read$/ )
            {
                return 1;
            }
            else
            {
                $point =~ s/_read$/_root/;
            }
        }
    }

    my $res = $ua->get( "$pmspoint?point=$point$treestr&cookie=$cookie" );
    if($res->is_success)
    {
        my $v = eval{decode_json $res->decoded_content};
        return $v->{data} if $v->{stat};
    }
    die $res->content;
};
1
